02. Demo: Backtesting Preparation in Python
Cd13650 C5 L4 Demo 1 V2
Back Testing Demo: Preparations Overview
Understand essential steps for preparing back testing data:
- Selecting Historical Period: Choose the timeframe for analysis. Example: 2008-2009 encompassing six months of raw daily data.
- Data Preparation:
- Clean data: Check and handle null values using forward filling.
- Drop remaining NaN rows.
- Define necessary features like MA20 and Bollinger Bands.
- State Space Matrix: Define using chosen feature values (e.g., close, upper and lower Bollinger Bands).
- Normalization:
- Apply standard normalization using libraries like Sklearn.
- Ensure normalized data is plotted for visualization.
- Data Conversion:
- Convert dataframe into numpy arrays for model input.
- Exclude non-numeric columns (e.g., date).
Following the preparation framework allows efficient back testing:
- Copy agent class and relevant functions from training code.
- Set parameters for the pre-trained model, including window size and number of training episodes.
This groundwork leads into the next stage: designing a back test loop.